/**
 * Created by Administrator on 2017/7/13 0013.
 */
require(["jquery","bbcare","scprit/department/vm/queueManagement/createQueue-data.js",
    "scprit/department/vm/queueManagement/createQueue-ajax.js",
    "scprit/department/vm/queueManagement/createQueue-event.js"],function($,$bb,$tpl,$ajax,$event) {
    var queueId="";
    queueId=$bb.getPageParams();
   // console.log(queueId);
   // queueId='12Y6w2ie6cqymt72BSQP';
    if(queueId){
        //获取队列信息：
        var paramsDetails={"queueId":queueId};
        var paramsDetailsFn=function(data){
            $tpl.pageInit({"id":"#input-List",'data':data.data});
            //方案初始化：
            var paramsDetailsFollow={
                page:1
            };
            var fnFollowDetails = function(follow){
                follow.data.schemeId=data.data.schemeId;
                follow.data.schemeName=data.data.schemeName;
                $tpl.queuelist({"id":"#followup-hdfp","data":follow.data});
            };
            $ajax.followup(paramsDetailsFollow,fnFollowDetails);
            $event.isNumber();
        }
        $ajax.getQueueDetails(paramsDetails,paramsDetailsFn);

        //队列医生：
        var queueDoctorParams={
            "queueId":queueId
        }
        var queueDoctorFn=function(data){
            var roleFn = function(dt){
                for(var i=0;i<data.data.length;i++){
                    data.data[i].roles=dt.data;
                }
                $tpl.doctorRoleList({"id":"#doctor-roleList","data":data.data});
            }
            $ajax.managementList(roleFn);
            $("#checkAll").click($event.isAllChecked);
            $("input[name='isCheck']").click($event.isChecked);
        }
        $ajax.getQueueDoctors(queueDoctorParams,queueDoctorFn);

        $("#btnSubmit").click(function(){
            $event.toSubmit(queueId)
        });

    }else{
        $tpl.pageInit({"id":"#input-List"});
        //方案初始化：
        var paramsFollow={
            page:1
        };
        var fnFollow = function(data){
            $tpl.queuelist({"id":"#followup-hdfp","data":data.data});
        };
        $ajax.followup(paramsFollow,fnFollow);

        //管理列表初始化：
        var fnDoctor=function(data){
            var roles=data.data;
            var doctor=function(data2){
                $tpl.dataDeal(data2,roles);
                $tpl.doctorRoleList({"id":"#doctor-roleList","data":data2.data});
                $("#checkAll").click($event.isAllChecked);
                $("input[name='isCheck']").click($event.isChecked);
            };
            $ajax.doctorRole(doctor)
        };
        $ajax.managementList(fnDoctor);
        $("#btnSubmit").click(function(){
            $event.toSubmit();
        });
    }

    //上传：
    var upLoadFn=function(data){
        $("input[type='file']").attr("logo-src",data.data);
    };
    $("#input-List").on("click","#logo-click",function(){
        $event.toUpload(upLoadFn);
    });
    $event.isNumber();
    $(window).resize(function(){
        var boxWidth=$(".box").width();
        var width1=$(".col-label").width();
        $(".col-label-intro").width(width1);
        $(".col-input-intro").width(boxWidth-width1-39);
    });
});